package Example2;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Locale;
import java.util.Objects;

//当我们需要给一些自定义类型添加比较功能的时候，在元素的内部实现比较，就需要实现Comparable接口。
public class Student implements Comparable<Student> {

    private String name;
    private int score;

    public Student(){

    }

    public Student(String name,int score){
        this.name=name;
        this.score=score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return this.score < student.score;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, score);
    }

    @Override
    public int compareTo(Student stu) {
        Collator collator=Collator.getInstance(Locale.CHINESE);
        CollationKey s1 = collator.getCollationKey(this.name);
        CollationKey s2 = collator.getCollationKey(stu.name);
        return s1.compareTo(s2);
    }
}
